﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using E_Shop.Common;
using ESHOP.DAO;
using ESHOP.UTIL;
using ESHOP.Domain;


namespace E_Shop
{
    public partial class CompanyPostNewSellLead : Authentication
    {

        private DanhMucDAO _danhMucDao = new DanhMucDAO();
        private QuocGiaDAO _quocGia = new QuocGiaDAO();
        private SellLeadDao _sellLeadDao = new SellLeadDao();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                CommonFunc.BindDropDownList(ddlcategory, _danhMucDao.GetList(), "TENDM", "ID", true);
                CommonFunc.BindDropDownList(dllregion, _quocGia.GetList(), "TENQUOCGIA", "ID", true);
            }
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                SELL sellObject = new SELL();
                sellObject.CATAGORY_ID = ddlcategory.SelectedValue;
                sellObject.MAQUOCGIA = dllregion.SelectedValue;
                string savePath = Server.MapPath("~/Images/Product/" + fuImage.FileName);
                if (fuImage.HasFile)
                {

                    fuImage.SaveAs(savePath);
                }
                String fileName = fuImage.FileName;
                sellObject.HINHANH = fileName;
                sellObject.ISHOW = false;
                sellObject.KEYWORD = txtKeyword.Text.Trim();
                sellObject.SUBJECT = txtSubject.Text.Trim();
                sellObject.DESCRIPTION = txtmota.Text.Trim();
                sellObject.MADM = ddlcategory.SelectedValue;
                sellObject.ID = _sellLeadDao.NewId();
                sellObject.NGAYDANG = DateTime.Now;
                sellObject.MACONGTY = Acount.MACT;
                if (_sellLeadDao.AddNew(sellObject) == 1)
                {
                    ShowInfor("Add Selling Success");
                }
                else
                {
                    ShowError("Add Selling fail!");
                }
            }
            catch
            {
                return;
            }
        }
    }
}